package ljl.alg.wangzheng_camp.round1.tree;

import commons.TreeNode;

import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;

/**
 * 我以为你会了
 * 结果你不会
 * */
public class _offer34_path_sum {
    
    LinkedList<Integer> path = new LinkedList<>();
    List<List<Integer>> res = new LinkedList<>();
    public List<List<Integer>> pathSum(TreeNode root, int target) {
        dfs(root, target);
        return res;
    }
    void dfs(TreeNode root, int target) {
        if (root == null) return;
        target -= root.val;
        path.offer(root.val);
        if (target == 0 && root.left == null && root.right == null) {
            res.add(new ArrayList<>(path));
            path.pollLast();
            return;
        }
        dfs(root.left, target);
        dfs(root.right, target);
        path.pollLast();
    }
}
